import req from '../utils/req.js';

// 网络状态服务模块
class NetworkService {
  // 获取当前网络状态
  async getCurrentStatus() {
    try {
      const response = await req.get('/network/current-status');
      return response.data;
    } catch (error) {
      console.error('获取当前网络状态失败:', error);
      throw error;
    }
  }

  // 获取历史数据
  async getHistoryData(days = 7) {
    try {
      const response = await req.get(`/network/history?days=${days}`);
      return response.data;
    } catch (error) {
      console.error('获取历史数据失败:', error);
      throw error;
    }
  }

  // 获取实时监测指标
  async getRealtimeMetrics() {
    try {
      const response = await req.get('/network/realtime-metrics');
      return response.data;
    } catch (error) {
      console.error('获取实时监测指标失败:', error);
      throw error;
    }
  }

  // 警报功能已移除

  // 生成模拟数据
  async generateMockData() {
    try {
      const response = await req.post('/network/generate-mock-data');
      return response.data;
    } catch (error) {
      console.error('生成模拟数据失败:', error);
      throw error;
    }
  }

  // 监控相关接口
  // 启动监控
  async startMonitoring() {
    try {
      const response = await req.post('/network/monitoring/start');
      return response.data;
    } catch (error) {
      console.error('启动监控失败:', error);
      throw error;
    }
  }

  // 停止监控
  async stopMonitoring() {
    try {
      const response = await req.post('/network/monitoring/stop');
      return response.data;
    } catch (error) {
      console.error('停止监控失败:', error);
      throw error;
    }
  }

  // 获取监控状态
  async getMonitoringStatus() {
    try {
      const response = await req.get('/network/monitoring/status');
      return response.data;
    } catch (error) {
      console.error('获取监控状态失败:', error);
      throw error;
    }
  }
}

export default new NetworkService();